import * as actionTypes from './constant'
import { fromJS } from 'immutable'
import { playMode } from '../../../api/config'

const defaultState = fromJS({
  fullScreen: false, // 播放器是否是全屏模式
  playingState: false,
  sequencePlayList: [], // 播放的顺序列表
  playList: [],
  mode: playMode.sequence, // 播放模式
  currentIndex: -1, // 当前歌曲在播放列表的索引位置
  showPlayList: false,
  currentSong: {}
})

const reducer = (state = defaultState, action) => {
  switch (action.type) {
    case actionTypes.SET_FULL_SCREEN:
      return state.set('fullScreen', action.data)
    case actionTypes.SET_PLAYING_STATE:
      return state.set('playingState', action.data)
    case actionTypes.SET_SEQUENCE_PLAY_LIST:
      return state.set('sequencePlayList', action.data)
    case actionTypes.SET_PLAY_LIST:
      return state.set('playList', action.data)
    case actionTypes.SET_MODE:
      return state.set('mode', action.data)
    case actionTypes.SET_CURRENT_INDEX:
      return state.set('currentIndex', action.data)
    case actionTypes.SET_SHOW_PLAY_LIST:
      return state.set('showPlayList', action.data)
    case actionTypes.SET_CURRENT_SONG:
      return state.set('currentSong', action.data)
    default:
      return state
  }
}

export default reducer
